<template>
	<view class="padding30rpx">
		<view v-if="jname">

			当前选择：<text style="color: #00A29A;">
				{{jname||''}}
			</text>
		</view>
		<view class="fontSize32rpx" style="font-weight: bold;">请选择学习岗位</view>

		<u-collapse>
			<u-collapse-item class="line" :title="item.departmentName" v-for="(item, index) in itemList" :key="index">
				<view v-for="(item1,index1) in item.tstationList" :key="index">
					<view class="dis choice">
						<view style="display: flex;align-items: center;">
							<label>{{item1.tstation.jname}}</label>
							<image v-if="item1.status == true" src="../../../static/term/ga.png" class="huiyuan">
							</image>
						</view>
						<view class="choice_btn" @tap="enter(item.tstationList,index1)">选择</view>
					</view>
				</view>
			</u-collapse-item>
		</u-collapse>
		<view class="btmbox">
			<button @click="open">开始学习</button>
		</view>
		<view style="height: 150rpx;"></view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				/**
				 * 部门
				 * */
				itemList: [],
				show: false,
				pid: '',
				jname: ''
			}
		},
		onLoad() {
			this.init()
		},
		methods: {

			open() {
				if (this.pid == '') {
					uni.showToast({
						icon: 'none',
						title: '请选择学习岗位'
					})
					return
				}
				this.selectUserYESMember()

			},
			init() {
				//查询当前用户是否未岗位会员
				this.selectUserYESMember()
				//查询当前用户是否选择岗位
				this.selectPostMembersList()
			},
			selectUserYESMember() {
				uni.request({
					method: 'GET',
					url: this.$api + '/app/UserController/updateUserPost',
					data: {
						pid: this.pid
					},
					header: {
						'token': uni.getStorageSync('token')
					},
					success: (res) => {
						console.log(res)
						if (res.data.code == 200) {


							uni.switchTab({
								url: '../study'
							})
						}
					},
					fail: (err) => {
						console.log(err)
					}
				})

			},
			selectPostMembersList() {
				uni.request({
					method: 'GET',
					url: this.$api + '/app/PostController/selectPostMembersList',
					data: {},
					header: {
						'token': uni.getStorageSync('token')
					},
					success: (res) => {
						console.log(res.data, '查询当前用户是否选择岗位')
						if (res.data.code == 401) {
							uni.navigateTo({
								url: '/pagesB/login/login'
							})
						}
						if (res.data.code == 200) {
							this.itemList = res.data.data
						} else {

						}
					}
				})
			},
			//选择
			enter(i, k) {
				console.log(i, k)
				uni.showToast({
					icon: 'none',
					title: `选择了` + i[k].tstation.jname,

				})
				this.jname = i[k].tstation.jname
				this.pid = i[k].tstation.id
			},
		}
	}
</script>

<style lang="scss" scoped>
	.choice_open {
		width: 49%;
		text-align: center;
	}

	.choice_zan {
		border-right: 1rpx solid #dcdcdc;
		text-align: center;
		width: 49%;
		color: #666666;
	}

	.huiyuan {
		width: 35rpx;
		height: 26rpx;
		margin-left: 20rpx;
	}

	.hui_img {
		width: 200rpx;
		height: 190rpx;
	}

	.choice-line {
		border-top: 1rpx solid #dcdcdc;
		height: 80rpx;
		line-height: 80rpx;
	}

	.btmbox {
		position: fixed;
		bottom: 10rpx;
		width: 92%;
		// margin-left: 4%;
	}

	button {
		background: #00A29A;
		color: #FFFFFF;
		width: 100%;
	}

	.choice {
		display: flex;
		margin-bottom: 5rpx;
		align-items: center;
	}

	.choice_btn {
		background: #00A29A;
		border-radius: 10rpx;
		padding: 10rpx 40rpx;
		color: #FFFFFF;
	}
</style>
